/**
 *
 * by littlefean
 */

window.onload = function () {
    let test = document.querySelector(`.test`);
    let ans = document.querySelector(`.ans`);
    test.onblur = function () {
        if (isP(+test.value)) {
            ans.innerHTML = "是质数";
        } else {
            ans.innerHTML = "不是质数";
        }
    }

    /**
     * 检测一个数是否是质数
     * @param n
     */
    function isP(n) {
        if (n < 2) {
            return false;
        }
        for (let i = 2; i < Math.ceil(n ** 0.5); i++) {
            if (n % i === 0) {
                return false;
            }
        }
        return true;
    }

    let table = document.querySelector(`.table`);

    for (let i = 0; i < 10000; i++) {
        let box = div(i.toString(), "numberBox");
        if (isP(i)) {
            box.classList.add("flag");
        }
        table.appendChild(box);
    }

}

